import { http } from "@/utils/http";
import { baseURLApi } from "./utils";
export type UserResult = {
  code: Number;
  data: {
    /** 头像 */
    avatar: string;
    /** 用户名 */
    username: string;
    /** 昵称 */
    nickname: string;
    /** 当前登录用户的角色 */
    roles: Array<string>;
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: number;
  };
  msg: string;
};

/**
 * UpdateProfileCommand
 */
export interface UserProfileRequest {
  email?: string;
  nickname?: string;
  mobile?: string;
  gender?: number;
  id?: number;
}

/**
 * ResetPasswordCommand
 */
export interface ResetPasswordRequest {
  newPassword?: string;
  oldPassword?: string;
  confirmPassword?: string;
  userId?: number;
}

/**
 * 修改密码
 */
export interface PasswordRequest {
  userId: number;
  password: string;
}

export type RefreshTokenResult = {
  code: Number;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: number;
  };
  msg: string;
};

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", baseURLApi("/auth/login"), { data });
};

/** 刷新`token` */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>(
    "post",
    baseURLApi("/auth/refreshToken"),
    { data }
  );
};
